// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

use crate::control::client::*;

impl StorageControl {
    /// Returns a builder for [StorageControl].
    ///
    /// ```no_run
    /// # tokio_test::block_on(async {
    /// # use google_cloud_storage::client::StorageControl;
    /// let client = StorageControl::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> ClientBuilder {
        gax::client_builder::internal::new_builder(client_builder::Factory)
    }

    /// Permanently deletes an empty bucket.
    /// The request fails if there are any live or
    /// noncurrent objects in the bucket, but the request succeeds if the
    /// bucket only contains soft-deleted objects or incomplete uploads, such
    /// as ongoing XML API multipart uploads. Does not permanently delete
    /// soft-deleted objects.
    ///
    /// When this API is used to delete a bucket containing an object that has a
    /// soft delete policy
    /// enabled, the object becomes soft deleted, and the
    /// `softDeleteTime` and `hardDeleteTime` properties are set on the
    /// object.
    ///
    /// Objects and multipart uploads that were in the bucket at the time of
    /// deletion are also retained for the specified retention duration. When
    /// a soft-deleted bucket reaches the end of its retention duration, it
    /// is permanently deleted. The `hardDeleteTime` of the bucket always
    /// equals
    /// or exceeds the expiration time of the last soft-deleted object in the
    /// bucket.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.buckets.delete` IAM permission on the bucket.
    pub fn delete_bucket(&self) -> crate::builder::storage_control::DeleteBucket {
        self.storage.delete_bucket()
    }

    /// Returns metadata for the specified bucket.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.buckets.get`
    /// IAM permission on
    /// the bucket. Additionally, to return specific bucket metadata, the
    /// authenticated user must have the following permissions:
    ///
    /// - To return the IAM policies: `storage.buckets.getIamPolicy`
    /// - To return the bucket IP filtering rules: `storage.buckets.getIpFilter`
    pub fn get_bucket(&self) -> crate::builder::storage_control::GetBucket {
        self.storage.get_bucket()
    }

    /// Creates a new bucket.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.buckets.create` IAM permission on the bucket.
    /// Additionally, to enable specific bucket features, the authenticated user
    /// must have the following permissions:
    ///
    /// - To enable object retention using the `enableObjectRetention` query
    ///   parameter: `storage.buckets.enableObjectRetention`
    /// - To set the bucket IP filtering rules: `storage.buckets.setIpFilter`
    pub fn create_bucket(&self) -> crate::builder::storage_control::CreateBucket {
        self.storage.create_bucket()
    }

    /// Retrieves a list of buckets for a given project, ordered
    /// lexicographically by name.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.buckets.list` IAM permission on the bucket.
    /// Additionally, to enable specific bucket features, the authenticated
    /// user must have the following permissions:
    ///
    /// - To list the IAM policies: `storage.buckets.getIamPolicy`
    /// - To list the bucket IP filtering rules: `storage.buckets.getIpFilter`
    pub fn list_buckets(&self) -> crate::builder::storage_control::ListBuckets {
        self.storage.list_buckets()
    }

    /// Permanently locks the retention
    /// policy that is
    /// currently applied to the specified bucket.
    ///
    /// Caution: Locking a bucket is an
    /// irreversible action. Once you lock a bucket:
    ///
    /// - You cannot remove the retention policy from the bucket.
    /// - You cannot decrease the retention period for the policy.
    ///
    /// Once locked, you must delete the entire bucket in order to remove the
    /// bucket's retention policy. However, before you can delete the bucket, you
    /// must delete all the objects in the bucket, which is only
    /// possible if all the objects have reached the retention period set by the
    /// retention policy.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.buckets.update` IAM permission on the bucket.
    pub fn lock_bucket_retention_policy(
        &self,
    ) -> crate::builder::storage_control::LockBucketRetentionPolicy {
        self.storage.lock_bucket_retention_policy()
    }

    /// Updates a bucket. Changes to the bucket are readable immediately after
    /// writing, but configuration changes might take time to propagate. This
    /// method supports `patch` semantics.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.buckets.update` IAM permission on the bucket.
    /// Additionally, to enable specific bucket features, the authenticated user
    /// must have the following permissions:
    ///
    /// - To set bucket IP filtering rules: `storage.buckets.setIpFilter`
    /// - To update public access prevention policies or access control lists
    ///   (ACLs): `storage.buckets.setIamPolicy`
    pub fn update_bucket(&self) -> crate::builder::storage_control::UpdateBucket {
        self.storage.update_bucket()
    }

    /// Concatenates a list of existing objects into a new object in the same
    /// bucket. The existing source objects are unaffected by this operation.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires the `storage.objects.create` and `storage.objects.get` IAM
    /// permissions to use this method. If the new composite object
    /// overwrites an existing object, the authenticated user must also have
    /// the `storage.objects.delete` permission. If the request body includes
    /// the retention property, the authenticated user must also have the
    /// `storage.objects.setRetention` IAM permission.
    pub fn compose_object(&self) -> crate::builder::storage_control::ComposeObject {
        self.storage.compose_object()
    }

    /// Deletes an object and its metadata. Deletions are permanent if versioning
    /// is not enabled for the bucket, or if the generation parameter is used, or
    /// if soft delete is not
    /// enabled for the bucket.
    /// When this API is used to delete an object from a bucket that has soft
    /// delete policy enabled, the object becomes soft deleted, and the
    /// `softDeleteTime` and `hardDeleteTime` properties are set on the object.
    /// This API cannot be used to permanently delete soft-deleted objects.
    /// Soft-deleted objects are permanently deleted according to their
    /// `hardDeleteTime`.
    ///
    /// You can use the [`RestoreObject`][google.storage.v2.Storage.RestoreObject]
    /// API to restore soft-deleted objects until the soft delete retention period
    /// has passed.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.objects.delete` IAM permission on the bucket.
    ///
    /// [google.storage.v2.Storage.RestoreObject]: crate::client::StorageControl::restore_object
    pub fn delete_object(&self) -> crate::builder::storage_control::DeleteObject {
        self.storage.delete_object()
    }

    /// Restores a
    /// soft-deleted object.
    /// When a soft-deleted object is restored, a new copy of that object is
    /// created in the same bucket and inherits the same metadata as the
    /// soft-deleted object. The inherited metadata is the metadata that existed
    /// when the original object became soft deleted, with the following
    /// exceptions:
    ///
    /// - The `createTime` of the new object is set to the time at which the
    ///   soft-deleted object was restored.
    /// - The `softDeleteTime` and `hardDeleteTime` values are cleared.
    /// - A new generation is assigned and the metageneration is reset to 1.
    /// - If the soft-deleted object was in a bucket that had Autoclass enabled,
    ///   the new object is
    ///   restored to Standard storage.
    /// - The restored object inherits the bucket's default object ACL, unless
    ///   `copySourceAcl` is `true`.
    ///
    /// If a live object using the same name already exists in the bucket and
    /// becomes overwritten, the live object becomes a noncurrent object if Object
    /// Versioning is enabled on the bucket. If Object Versioning is not enabled,
    /// the live object becomes soft deleted.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires the following IAM permissions to use this method:
    ///
    /// - `storage.objects.restore`
    /// - `storage.objects.create`
    /// - `storage.objects.delete` (only required if overwriting an existing
    ///   object)
    /// - `storage.objects.getIamPolicy` (only required if `projection` is `full`
    ///   and the relevant bucket
    ///   has uniform bucket-level access disabled)
    /// - `storage.objects.setIamPolicy` (only required if `copySourceAcl` is
    ///   `true` and the relevant
    ///   bucket has uniform bucket-level access disabled)
    pub fn restore_object(&self) -> crate::builder::storage_control::RestoreObject {
        self.storage.restore_object()
    }

    /// Retrieves object metadata.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.objects.get` IAM permission on the bucket.
    /// To return object ACLs, the authenticated user must also have
    /// the `storage.objects.getIamPolicy` permission.
    pub fn get_object(&self) -> crate::builder::storage_control::GetObject {
        self.storage.get_object()
    }

    /// Updates an object's metadata.
    /// Equivalent to JSON API's `storage.objects.patch` method.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires `storage.objects.update` IAM permission on the bucket.
    pub fn update_object(&self) -> crate::builder::storage_control::UpdateObject {
        self.storage.update_object()
    }

    /// Retrieves a list of objects matching the criteria.
    ///
    /// **IAM Permissions**:
    ///
    /// The authenticated user requires `storage.objects.list`
    /// IAM permission to use this method. To return object ACLs, the
    /// authenticated user must also
    /// have the `storage.objects.getIamPolicy` permission.
    pub fn list_objects(&self) -> crate::builder::storage_control::ListObjects {
        self.storage.list_objects()
    }

    /// Rewrites a source object to a destination object. Optionally overrides
    /// metadata.
    pub fn rewrite_object(&self) -> crate::builder::storage_control::RewriteObject {
        self.storage.rewrite_object()
    }

    /// Moves the source object to the destination object in the same bucket.
    /// This operation moves a source object to a destination object in the
    /// same bucket by renaming the object. The move itself is an atomic
    /// transaction, ensuring all steps either complete successfully or no
    /// changes are made.
    ///
    /// **IAM Permissions**:
    ///
    /// Requires the following IAM permissions to use this method:
    ///
    /// - `storage.objects.move`
    /// - `storage.objects.create`
    /// - `storage.objects.delete` (only required if overwriting an existing
    ///   object)
    pub fn move_object(&self) -> crate::builder::storage_control::MoveObject {
        self.storage.move_object()
    }

    /// Creates a new folder. This operation is only applicable to a hierarchical
    /// namespace enabled bucket.
    pub fn create_folder(&self) -> crate::builder::storage_control::CreateFolder {
        self.control.create_folder()
    }

    /// Permanently deletes an empty folder. This operation is only applicable to a
    /// hierarchical namespace enabled bucket.
    pub fn delete_folder(&self) -> crate::builder::storage_control::DeleteFolder {
        self.control.delete_folder()
    }

    /// Returns metadata for the specified folder. This operation is only
    /// applicable to a hierarchical namespace enabled bucket.
    pub fn get_folder(&self) -> crate::builder::storage_control::GetFolder {
        self.control.get_folder()
    }

    /// Retrieves a list of folders. This operation is only applicable to a
    /// hierarchical namespace enabled bucket.
    pub fn list_folders(&self) -> crate::builder::storage_control::ListFolders {
        self.control.list_folders()
    }

    /// Renames a source folder to a destination folder. This operation is only
    /// applicable to a hierarchical namespace enabled bucket. During a rename, the
    /// source and destination folders are locked until the long running operation
    /// completes.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn rename_folder(&self) -> crate::builder::storage_control::RenameFolder {
        self.control.rename_folder()
    }

    /// Returns the storage layout configuration for a given bucket.
    pub fn get_storage_layout(&self) -> crate::builder::storage_control::GetStorageLayout {
        self.control.get_storage_layout()
    }

    /// Creates a new managed folder.
    pub fn create_managed_folder(&self) -> crate::builder::storage_control::CreateManagedFolder {
        self.control.create_managed_folder()
    }

    /// Permanently deletes an empty managed folder.
    pub fn delete_managed_folder(&self) -> crate::builder::storage_control::DeleteManagedFolder {
        self.control.delete_managed_folder()
    }

    /// Returns metadata for the specified managed folder.
    pub fn get_managed_folder(&self) -> crate::builder::storage_control::GetManagedFolder {
        self.control.get_managed_folder()
    }

    /// Retrieves a list of managed folders for a given bucket.
    pub fn list_managed_folders(&self) -> crate::builder::storage_control::ListManagedFolders {
        self.control.list_managed_folders()
    }

    /// Creates an Anywhere Cache instance.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_anywhere_cache(&self) -> crate::builder::storage_control::CreateAnywhereCache {
        self.control.create_anywhere_cache()
    }

    /// Updates an Anywhere Cache instance. Mutable fields include `ttl` and
    /// `admission_policy`.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn update_anywhere_cache(&self) -> crate::builder::storage_control::UpdateAnywhereCache {
        self.control.update_anywhere_cache()
    }

    /// Disables an Anywhere Cache instance. A disabled instance is read-only. The
    /// disablement could be revoked by calling ResumeAnywhereCache. The cache
    /// instance will be deleted automatically if it remains in the disabled state
    /// for at least one hour.
    pub fn disable_anywhere_cache(&self) -> crate::builder::storage_control::DisableAnywhereCache {
        self.control.disable_anywhere_cache()
    }

    /// Pauses an Anywhere Cache instance.
    pub fn pause_anywhere_cache(&self) -> crate::builder::storage_control::PauseAnywhereCache {
        self.control.pause_anywhere_cache()
    }

    /// Resumes a disabled or paused Anywhere Cache instance.
    pub fn resume_anywhere_cache(&self) -> crate::builder::storage_control::ResumeAnywhereCache {
        self.control.resume_anywhere_cache()
    }

    /// Gets an Anywhere Cache instance.
    pub fn get_anywhere_cache(&self) -> crate::builder::storage_control::GetAnywhereCache {
        self.control.get_anywhere_cache()
    }

    /// Lists Anywhere Cache instances for a given bucket.
    pub fn list_anywhere_caches(&self) -> crate::builder::storage_control::ListAnywhereCaches {
        self.control.list_anywhere_caches()
    }

    /// Returns the Project scoped singleton IntelligenceConfig resource.
    pub fn get_project_intelligence_config(
        &self,
    ) -> crate::builder::storage_control::GetProjectIntelligenceConfig {
        self.control.get_project_intelligence_config()
    }

    /// Updates the Project scoped singleton IntelligenceConfig resource.
    pub fn update_project_intelligence_config(
        &self,
    ) -> crate::builder::storage_control::UpdateProjectIntelligenceConfig {
        self.control.update_project_intelligence_config()
    }

    /// Returns the Folder scoped singleton IntelligenceConfig resource.
    pub fn get_folder_intelligence_config(
        &self,
    ) -> crate::builder::storage_control::GetFolderIntelligenceConfig {
        self.control.get_folder_intelligence_config()
    }

    /// Updates the Folder scoped singleton IntelligenceConfig resource.
    pub fn update_folder_intelligence_config(
        &self,
    ) -> crate::builder::storage_control::UpdateFolderIntelligenceConfig {
        self.control.update_folder_intelligence_config()
    }

    /// Returns the Organization scoped singleton IntelligenceConfig resource.
    pub fn get_organization_intelligence_config(
        &self,
    ) -> crate::builder::storage_control::GetOrganizationIntelligenceConfig {
        self.control.get_organization_intelligence_config()
    }

    /// Updates the Organization scoped singleton IntelligenceConfig resource.
    pub fn update_organization_intelligence_config(
        &self,
    ) -> crate::builder::storage_control::UpdateOrganizationIntelligenceConfig {
        self.control.update_organization_intelligence_config()
    }

    /// Gets the IAM policy for a specified bucket.
    /// The `resource` field in the request should be
    /// `projects/_/buckets/{bucket}` for a bucket, or
    /// `projects/_/buckets/{bucket}/managedFolders/{managedFolder}`
    /// for a managed folder.
    pub fn get_iam_policy(&self) -> crate::builder::storage_control::GetIamPolicy {
        self.control.get_iam_policy()
    }

    /// Updates an IAM policy for the specified bucket.
    /// The `resource` field in the request should be
    /// `projects/_/buckets/{bucket}` for a bucket, or
    /// `projects/_/buckets/{bucket}/managedFolders/{managedFolder}`
    /// for a managed folder.
    pub fn set_iam_policy(&self) -> crate::builder::storage_control::SetIamPolicy {
        self.control.set_iam_policy()
    }

    /// Tests a set of permissions on the given bucket, object, or managed folder
    /// to see which, if any, are held by the caller.
    /// The `resource` field in the request should be
    /// `projects/_/buckets/{bucket}` for a bucket,
    /// `projects/_/buckets/{bucket}/objects/{object}` for an object, or
    /// `projects/_/buckets/{bucket}/managedFolders/{managedFolder}`
    /// for a managed folder.
    pub fn test_iam_permissions(&self) -> crate::builder::storage_control::TestIamPermissions {
        self.control.test_iam_permissions()
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> crate::builder::storage_control::GetOperation {
        self.control.get_operation()
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: crate::stub::StorageControl + 'static,
    {
        let stub = std::sync::Arc::new(stub);
        Self {
            storage: crate::generated::gapic::client::StorageControl::from_stub(stub.clone()),
            control: crate::generated::gapic_control::client::StorageControl::from_stub(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let storage = crate::generated::gapic::client::StorageControl::new(config.clone()).await?;
        let control = crate::generated::gapic_control::client::StorageControl::new(config).await?;
        Ok(Self { storage, control })
    }
}
